//
//  DigitalDepositViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/13.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "DigitalDepositViewController.h"

@interface DigitalDepositViewController ()

@property (weak, nonatomic) IBOutlet UIImageView *QRImageView;
@property (weak, nonatomic) IBOutlet UILabel *BTCPath;
@property (weak, nonatomic) IBOutlet UIView *QRBgView;
@property (weak, nonatomic) IBOutlet UIImageView *addressImage;
@property (weak, nonatomic) IBOutlet UILabel *addressTitle;
@property (weak, nonatomic) IBOutlet UILabel *message;
@property (weak, nonatomic) IBOutlet UILabel *tipsTitle;

@end

@implementation DigitalDepositViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = [NSString stringWithFormat:@"%@ %@", JFMainLocalizedString(@"deposit.deposit"), self.asset_address];
    self.addressTitle.text = [NSString stringWithFormat:@"%@ %@", self.asset_address, JFMainLocalizedString(@"myAssets.deposit-address3")];
    self.tipsTitle.text = JFMainLocalizedString(@"withdraw.tips");
    self.message.text = JFMainLocalizedString(@"myAssets.deposit-address2");
    
    
    [self.QRImageView setImage:[self creatQRcodeWithUrlstring:self.public_address]];
    [self.addressImage setImage:[UIImage imageNamed:self.asset_address]];
    self.BTCPath.text = self.public_address;
    self.QRBgView.layer.shadowColor = UIColorFromHex(0xDFE6ED).CGColor;
    self.QRBgView.layer.shadowOffset = CGSizeMake(3, 3);
    self.QRImageView.backgroundColor = [UIColor whiteColor];
}

- (UIImage *)creatQRcodeWithUrlstring:(NSString *)urlString{
    // 1.实例化二维码滤镜
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
    // 2.恢复滤镜的默认属性 (因为滤镜有可能保存上一次的属性)
    [filter setDefaults];
    // 3.将字符串转换成NSdata
    NSData *data  = [urlString dataUsingEncoding:NSUTF8StringEncoding];
    // 4.通过KVO设置滤镜, 传入data, 将来滤镜就知道要通过传入的数据生成二维码
    [filter setValue:data forKey:@"inputMessage"];
    // 5.生成二维码
    CIImage *outputImage = [filter outputImage];
    return [UIImage imageWithCIImage:outputImage];
}

- (IBAction)pasteAction:(id)sender {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = self.public_address;
    [SLRemindView showMessage:JFMainLocalizedString(@"myAssets.copy-success") toView:self.view];
}


@end
